<template>
  <div>
    <van-cell @click="detailFn">
    <template #title>
      <div class="titleBox">
        {{ item.title }}
        <!-- 判断如果只有一张图片,则这么显示 -->
        <img
          class="thumb"
          v-if="item.cover.type === 1"
          v-lazy='item.cover.images[0]'
        />
      </div>
      <!-- 判断如果有多张图片,则这么显示 -->
      <div class="thumb-box" v-if="item.cover.type > 1">
        <img
        class="thumb"
          v-for="(itemm, index) in item.cover.images"
          :key="index"
          v-lazy="itemm"
        />
      </div>
    </template>
    <template #label>
      <div class="msg">
        <div>
          <span>作者 {{ item.aut_name }}</span>
          <span>{{ item.comm_count }} 评论</span>
          <span>发布日期 {{ item.pubdate }}</span>
        </div>
        <van-icon name="cross"  @click.stop="clkFn" v-if="isShown"/>
      </div>
    </template>
  </van-cell>

  <van-action-sheet v-model="show" :actions="actions" @select="onSelect1" get-container='body' cancel-text="取消" />
  <van-action-sheet v-model="show2"  :actions="actions2" @select="onSelect2" get-container='body' cancel-text="返回" @cancel='cancelFn'/>

  </div>
</template>

<script>
import { firstActions, secondActions } from '@/api/reports.js'
export default {
  data () {
    return {
      show: false,
      actions: firstActions,
      actions2: secondActions,
      show2: false
    }
  },
  methods: {
    clkFn () {
      this.show = true
    },
    onSelect1 (action, index) {
      this.show = false
      if (action.name === '不感兴趣') {
        // 此时通知主页面,删除数据
        this.$emit('del', this.item)
      } else if (action.name === '反馈垃圾内容') {
        this.show2 = true
      } else {
      }
    },
    onSelect2 (action, index) {
      this.show2 = false
      this.$emit('del2', this.item, action)
    },
    cancelFn () {
      this.show = true
      this.show2 = false
    },
    detailFn () {
      this.$router.push({
        path: `/article/${this.item.art_id}`
      })
    }
  },
  props: {
    item: {
      type: Object,
      default () {
        return {}
      }
    },
    isShown: {
      type: Boolean,
      default: true
    }
  }
}
</script>

<style lang='less' scoped>
.titleBox {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.msg {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
